# from PIL import Image, ImageDraw, ImageFont

# # 创建图像实例
# out = Image.new("RGB", (394, 394), (255, 255, 255))

# fnt = ImageFont.truetype("C:\\Windows\\Fonts\\STZHONGS.TTF", 20)
# # get a drawing context
# d = ImageDraw.Draw(out)

# # draw multiline text
# d.multiline_text((10, 10), "产品中文名 	谷胱甘肽(还原型)谷胱甘肽(还原型)谷胱甘肽(还原型)", font=fnt, fill=(0, 0, 0))
# d.multiline_text((10, 40), "产品英文名 Glutathione reduced", font=fnt, fill=(0, 0, 0))
# d.multiline_text((10, 70), "纯度 99%生物技术级", font=fnt, fill=(0, 0, 0))
# d.multiline_text((10, 100), "颜色 白色结晶粉末", font=fnt, fill=(0, 0, 0))
# d.multiline_text((10, 130), "CAS 号 70-18-8", font=fnt, fill=(0, 0, 0))
# d.multiline_text((10, 160), "存储条件 2~8°C", font=fnt, fill=(0, 0, 0))

# out.show()
# out.save("out.png")

from PIL import Image, ImageDraw,ImageFont

# 创建一个新的394x394纯白图片
im = Image.new("RGB", (394, 394), (255, 255, 255))

# 创建可绘制对象
draw = ImageDraw.Draw(im)

# 定义行高和列宽以及表格的起始坐标
row_height = 40
col_width = 160
table_start = (10, 10)  # 表格起始坐标

# 画横线和竖线
for i in range(7):
    y = table_start[1] + i * row_height
    draw.line((table_start[0], y, table_start[0] + 2 * col_width, y), fill=128)
for i in range(3):
    x = table_start[0] + i * col_width
    draw.line((x, table_start[1], x, table_start[1] + 6 * row_height), fill=128)

# 表格内容
data = {
    "产品中文名": (0, 0),
    "谷胱甘肽(还原型)": (0, 1),
    "产品英文名": (1, 0),
    "Glutathione reduced": (1, 1),
    "纯度": (2, 0),
    "99%生物技术级": (2, 1),
    "颜色": (3, 0),
    "白色结晶粉末": (3, 1),
    "CAS 号": (4, 0),
    "70-18-8": (4, 1),
    "存储条件": (5, 0),
    "2~8°C": (5, 1),
}

# 写入表格内容
font_size = 20
font_path = "C:\\Windows\\Fonts\\STZHONGS.TTF"  # 字体文件路径，这里使用默认字体arial.ttf
font = ImageFont.truetype(font_path, font_size)
text_color = (0, 0, 0)  # 黑色

for text, position in data.items():
    cell_x = table_start[0] + position[1] * col_width
    cell_y = table_start[1] + position[0] * row_height
    draw.text((cell_x+ 10, cell_y+5), text, fill=text_color, font=font)

# 显示图片
im.show()
